﻿using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.JSON;
using Kingdee.BOS.Util;
using System;
using System.ComponentModel;
namespace Jac.XkDemo.BOS.Business.PlugIn
{
    /// <summary>
    /// 【表单插件】文本字段打开超链接
    /// </summary>
    [Description("【表单插件】文本字段打开超链接(图片)"), HotUpdate]
    public class TextFieldOpenUrlFormPlugInWL : AbstractDynamicFormPlugIn
    {
        public override void AfterBindData(EventArgs e)
        {
            base.AfterBindData(e);
            if (this.Model.GetValue("F_WNEG_Text_re51") != null)
            {
                this.Model.SetValue("F_WNEG_Text_re51", this.Model.GetValue("F_WNEG_Text_re51").ToString());
            }

        }
        public override void BeforeF7Select(BeforeF7SelectEventArgs e)
        {
            base.BeforeF7Select(e);
            if (e.FieldKey.EqualsIgnoreCase("F_WNEG_Text_re51"))
            {
                // 参考资料：https://vip.kingdee.com/article/81423104462710784
                // 生成Url地址
                var url = this.Model.GetValue("F_WNEG_Text_re51") as string;
                // 方式1：直接打开浏览器
                this.View.AddAction("ShowWebURL", url);
                // 方式2：打开Url地址
                //var webobj = new JSONObject();
                //webobj["source"] = url;
                //webobj["height"] = 600;
                //webobj["width"] = 800;
                //webobj["isweb"] = true; // 是否新弹出一个浏览器窗口（or选项卡）打开网页地址
                //webobj["title"] = "JPG";
                //this.View.AddAction("ShowKDWebbrowseForm", webobj);
                //this.View.SendDynamicFormAction(this.View);
            }
        }
    }
}

